<?php
namespace core;

class Model
{
    /**
     * 模型观察者集合
     * @var array
     */
    protected $observers;

    public function __construct()
    {
        if ('app\\model\\' === substr(get_class($this), 0, 10)) {
            $name = strtolower(str_replace('app\\model\\', '', get_class($this)));
            if (!empty(Config::get("model.{$name}"))) {

                $observers = Config::get("model.{$name}");

                foreach($observers as $class) {
                    $this->observers[] = new $class;
                }
            }
        }
    }

    public function notify($event)
    {
        foreach($this->observers as $observer) {
            $observer->update($event);
        }
    }
}